import { defineStore } from 'pinia'

const useCachedPageStore = defineStore('cached-page', {
  state: () => ({
    cachedViews: [],
  }),
  actions: {
    // 缓存页面
    addCachedView(view: string) {
      if (!this.cachedViews.includes(view)) {
        this.cachedViews.push(view)
      }
    },
    // 删除缓存页面
    deleteCachedView(view: string) {
      const index = this.cachedViews.indexOf(view)
      if (index > -1) {
        this.cachedViews.splice(index, 1)
      }
    },
  },
})

export default useCachedPageStore
